package com.yao.spider.zhihu.dao.Impl;

import com.yao.spider.zhihu.dao.IUserDao;
import com.yao.spider.zhihu.entity.User;
import com.yao.spider.zhihu.mapper.UserMapper;
import com.yao.spider.zhihu.utils.MyBatiesUtils;
import org.apache.ibatis.session.SqlSession;

import java.lang.reflect.ParameterizedType;

/**
 * Created by 单耀 on 2018/1/2.
 */
public class UserDaoImpl implements IUserDao{
    public void insertSelective(User o) {
        SqlSession session = MyBatiesUtils.getSqlSession(true);
        UserMapper userMapper = session.getMapper(UserMapper.class);
        User u = userMapper.selectByPrimaryKey(o.getUserToken());
        if (u == null) {
            userMapper.insertSelective(o);
        }
        session.close();
    }

    public void insert(Object o) {
        SqlSession session = MyBatiesUtils.getSqlSession(true);
        UserMapper userMapper = session.getMapper(UserMapper.class);
        userMapper.insert((User) o);
    }
}
